// 需要设置slider的宽度，用于计算中间位置
var app = getApp()
Page({
  data: {
    tabs: ["全部", "待付款", "待发货", "已完成"],
    sliderOffset: 0,
    sliderLeft: 0,
      statusName: ['待付款', '已付款', '已发货', '已完成','已失效']
  },
  //订单点击进入详情
  orderDetailClick : function(e){
    var thiz = this
    var id = e.currentTarget.dataset.id

    wx.navigateTo({
      url: '../order_detail/order_detail?order_id=' + id,
    })
  },

  onLoad: function (options) {
    var thiz = this

    var background_color = app.globalData.background_color

    wx.setNavigationBarColor({
      backgroundColor: background_color,
    })

    var domain = app.globalData.domain
    var orderListUrl = app.globalData.orderListInterface
    var domainImg = app.globalData.domain
    var user_id = app.globalData.inv_i

    thiz.setData({
      domain : domain,
      activeIndex: options.activeIndex,
      background: background_color,
      domainImg: domainImg,
    })

    wx.request({
      url: domain + orderListUrl,
      data:{
        format_type : 'json',
        api_cate: 'Order',
        api : 8001,
        status: 'all',
        model: "MINI",
        user_id: user_id
      },
      method: 'POST',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success : function(res){

        if(res.data.data.length > 0){
          var payOrder = []
          var unPayOrder = []
          var overPayOrder = []
          res.data.data.forEach(function (element, index) {
            if (element.status == 1) {
              payOrder.push(element)
            } else if (element.status == 0) {
              unPayOrder.push(element)
            } else if(element.status == 3) {
              overPayOrder.push(element)
            }
          })


          thiz.setData({
            allOrderArray: res.data.data,
            payOrder: payOrder,
            unPayOrder: unPayOrder,
            overPayOrder: overPayOrder,
          })

        }else{
          thiz.setData({
            allOrderArray: [],
            payOrder: [],
            unPayOrder: [],
            overPayOrder: [],
          })
        }
        
      }
    })

  },
  tabClick: function (e) {
    this.setData({
      activeIndex: e.currentTarget.id
    });
  }
});